<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Games</title>
</head>

<link rel="stylesheet" type="text/css" href="master.css" media="screen" />
<body>

<script type="text/javascript">
 function goback()
 {
	 <?php 
	 
	 if($_GET['pagesource'] == "friendlist")
	 {
		 $pagesource = "./friend/Friend.php";
		 
	 }
	 else if($_GET['pagesource'] == "usersearch")
	 {
		 $pagesource = "userSearch.php";
	 }
	 else if($_GET['pagesource'] == "pastGame")
	 {
		 $pagesource = "game/pastGame.php";
	 }
	  else if($_GET['pagesource'] == "Game")
	 {
		 $pagesource = "game/Game.php";
	 }
	  else if($_GET['pagesource'] == "joinedGame")
	 {
		 $pagesource = "game/joinedGame.php";
	 }
	 
	 ?>
	 
	 
	 document.forms['buttonform'].action = "<?=$pagesource?>";
	 document.forms['buttonform'].submit();
 }

</script>
  
  <fieldset><legend>Profile</legend>
  
  
<?php  
include("db.php");
session_start();
check_inactive();
authenticate_player(); 


$db = pg_connect('host=dbsrv1 dbname=csc309g7 user=csc309g7 password=aiboid4p');

$myuserid = $_SESSION['userid'];


if($db) 
{
	
	if($_GET['viewuserid'])
	{
		$id = $_GET['viewuserid'];
		
	}
	
  $query = "select username, name, email, sport_interested, skill_level from people where userid = $id";
  
  
  $result = pg_query($query);

  if ($result) {
  
    //echo "<img src='.pikachu.jpeg' alt='Join this game' width='16' height='14' border='0'>"
    while($data = pg_fetch_assoc($result))
	{
    
	echo "<h1> Name: " . $data ['name'] . "</h1>";
	echo "<h4> User account name: " . $data['username'] . "</h4>";
    echo "<h4> Email: " . $data['email'] . "</h4>";
    echo "<h4> Sport Interested: " . $data['sport_interested']  . "</h4>";
    echo "<h4> Skill Level: " . $data['skill_level']  . "</h4>";
    
    
    echo "<br/>";
    echo "<label>Operation:</label>\n";
    
   
	
	
	
	if(!check_friends($myuserid, $id))
	{
		echo "<form action='friend/Friend.php' method='post'>";
		echo "<input type='hidden' value='$id' name='addfriend'/><input type='submit' value='Add to friend list'/></form>";
	}
	else
	{
		echo "This user is in your friend list</br>";
	}
	echo "<FORM name='buttonform' method='post'><INPUT TYPE='button' VALUE='Go Back' ONCLICK='javascript:goback();'></FORM>";
   
   	
      }
  }

}


      
      
      
?>
    </body>
  </html>
